require "Common/define"
local json = require "cjson"

require "Logic/CtrlManager"
require "Logic/Config"
require "Common/functions"
require "Net/msgDispatcher"

--管理器--
OffLine = {};
local this = OffLine;

function OffLine.unrequire(moduleName)
  package.loaded[moduleName]=nil;
  _G[moduleName] = nil
end

function OffLine.loadTable(name)
  --local data = require("data/skill/"..name)
    local data = dofile("data/"..name)

  local convert={};
  for k,v in pairs(data) do
    if k~="_key_" then
      convert[k]={};
      for k2,v2 in pairs(data["_key_"]) do
        convert[k][v2]=data[k][k2];
      end
    end
  end
  
  local last={}
  for k,v in pairs(convert) do
      table.insert(last,v);
  end
  
  this.unrequire("data/skill/"..name);

  local json = require 'Common/dkjson'
  return json.encode(last);
  
end

function OffLine.loadData(name)
  local data = require("data/"..name)

  local convert={};

  for k,v in pairs(data) do
    if k~="_key_" then
      convert[k]={};
      for k2,v2 in pairs(data["_key_"]) do
        convert[k][v2]=data[k][k2];
      end
    end
  end
  this.unrequire("data/"..name);

  --local json = require 'cjson'
  --json.encode_sparse_array(true);

  local json = require 'Common/dkjson'
  local result = json.encode(convert);

  return result;
end

